package com.example.schooljava.service.impl;

import com.example.schooljava.pojo.entity.Route;
import com.example.schooljava.mapper.RouteMapper;
import com.example.schooljava.service.RouteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.schooljava.util.Result;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LDH
 * @since 2022/08/22
 */
@Service
public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {

    /**
     * 功能描述: 添加路由<br>
     * @Param: [route]
     * @Return: com.example.schooljava.util.Result
     * @Author: LDH
     * @Date: 2022/8/22 13:46
     */
    @Override
    public Result setRoute(Route route) {
        save(route);
        return new Result<>().OK(true,"添加路由成功");
    }

    /**
     * 功能描述: 删除路由<br>
     * @Param: [list]
     * @Return: com.example.schooljava.util.Result
     * @Author: LDH
     * @Date: 2022/8/22 13:46
     */
    @Override
    public Result delRoute(ArrayList<String> list) {
        for (String l : list) {
            for (Route route : list()) {
                if (Long.parseLong(l) == route.getId())
                    removeById(Long.parseLong(l));
            }
        }
        return new Result<>().OK(true,"删除路由成功");
    }
}
